#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

struct student
{
    int class;
    int num;
    char name[20];
};
void sortclass(struct student* pc,int n)
{
    int i = 0;
    int j = 0;
    for (j = 1; j < n - 1; j++)
    {
        for (i = 0; i < n-1; i++)
        {
            if (pc[i].class > pc[i + 1].class)
            {
                int tmp = 0;
                tmp = pc[i + 1].class;
                pc[i + 1].class = pc[i].class;
                pc[i].class = tmp;
                tmp = pc[i + 1].num;
                pc[i + 1].num = pc[i].num;
                pc[i].num = tmp;
                char arr[20];
                strcpy(arr, pc[i + 1].name);
                strcpy(pc[i + 1].name, pc[i].name);
                strcpy(pc[i].name, arr);

            }

        }
    }
}
void numsort(struct student* pc, int n)
{
    int i = 0;
    int j = 0;
    for (j = 1; j < n - 1; j++)
    {
        for (i = 0; i < n-1; i++)
        {
            if (pc[i].class == pc[i + 1].class && pc[i].num > pc[i + 1].num)
            {
                int tmp = 0;
                tmp = pc[i + 1].num;
                pc[i + 1].num = pc[i].num;
                pc[i].num = tmp;
                char arr[20];
                strcpy(arr, pc[i + 1].name);
                strcpy(pc[i + 1].name, pc[i].name);
                strcpy(pc[i].name, arr);
            }
        }
    }

}
int main()
{
    struct student arr[100];
    int n = 0;
    scanf("%d", &n);
    int i = 0;
    for (i = 0; i < n; i++)
    {
        scanf("%d%d%s", &arr[i].class, &arr[i].num, arr[i].name);
    }
    sortclass(arr,n);
    numsort(arr, n);
    for (i = 0; i < n; i++)
    {
        printf("%d %d %s\n", arr[i].class, arr[i].num, arr[i].name);
    }
    return 0;
}